﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System
{
    /// <summary>
    /// Collection of <see cref="DateTime"/> extension methods.
    /// </summary>
    public static class DateTimeUtils
    {
        /// <summary>
        /// Coerces resolution to seconds. Milliseconds and below are cut off.
        /// </summary>
        /// <param name="dt"></param>
        /// <returns>returns a new coerced DateTime instance</returns>
        public static DateTime CoerceSubseconds(this DateTime dt)
        {
            return new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
        }

        /// <summary>
        /// Returns true, if dateTime lies in the past.
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns>true, if dateTime is in past.</returns>
        [Pure]
        public static bool IsInPast(DateTime dateTime)
        {
            return (DateTime.Now.Ticks - dateTime.Ticks) > 0;
        }

        /// <summary>
        /// Returns true, if dateTime lies in the future.
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns>true, if dateTime lies in the future.</returns>
        [Pure]
        public static bool IsInFuture(DateTime dateTime)
        {
            return (dateTime.Ticks - DateTime.Now.Ticks) > 0;
        }
    }
}
